#! /bin/sh

set -e

DEV_WIKI_DIR=${DEV_WIKI_DIR:=./docs/dev-wiki}
HELP_WIKI_DIR=${HELP_WIKI_DIR:=./docs/help-wiki}
SRC_DIR=${PWD##*/}

if [ "$SRC_DIR" = "scripts" ]; then
    DEV_WIKI_DIR=../docs/dev-wiki
    HELP_WIKI_DIR=../docs/help-wiki
fi

for i in "$@"
do
case $i in
    --dev)
    DEV=true
    shift 
    ;;
    --user)
    USER=true
    shift 
    ;;
    *)    
    ;;
esac
done

WIKI_PATH=$SRC_DIR

if [ "$DEV" = true ]; then
    WIKI_PATH=$DEV_WIKI_DIR
elif [ "$USER" = true ]; then
    WIKI_PATH=$HELP_WIKI_DIR
else
    WIKI_PATH=$DEV_WIKI_DIR  
fi

if [ ! -d "$WIKI_PATH" ]; then
    echo "wiki dir doesnt exist: $WIKI_PATH"
    exit 1
else
    cd $WIKI_PATH
    echo "Wiki found in $WIKI_PATH"
    echo "Serving wiki on localhost:8000 :-)"
    echo "And to help you out i'll even launch the browser for you"
    xdg-open http://localhost:8000 && python -m SimpleHTTPServer
fi
    

    
